package com.leyou.item.service;

import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    //获取分类的列表
    public List<Category> queryCategoryByPid(Long id) {
        Category category = new Category();
        category.setParentId(id);
        return categoryMapper.select(category);
    }

    //获取回显得分类id
    public List<Category> queryByBrandId(Long bid) {
        return categoryMapper.queryByBrandId(bid);
    }

    //拓展查询分类名称
    public List<String> queryNamesByIds(List<Long> asList) {

        //selectByIDList方法是来自于通用mapper
        List<Category> categoryList = this.categoryMapper.selectByIdList(asList);
        List<String> list=new  ArrayList<>();
        for (Category category : categoryList) {
            list.add(category.getName());
        }
        return list;
       // return categoryList.stream().map(category -> category.getName()).collect(Collectors.toList());

    }
}
